<?php

namespace App\Model;


use Illuminate\Database\Eloquent\Model;

class UserAvatarLog extends Model
{
    protected $table = 'user_avatar_log';

    protected $fillable = ['user_id', 'role', 'detail', 'flag'];

    //正常
    const FLAG_OK = 1;
    //不可操作
    const FLAG_NO = 0;
    //违规
    const FLAG_BAD = -1;
    const FLAG_ING = 2;

    const FLAG = [
        self::FLAG_OK => '正常',
        self::FLAG_NO => '不可操作',
        self::FLAG_BAD => '违规',
        self::FLAG_ING => '待审核',
    ];


    public function userItem()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function userProfile()
    {
        return $this->belongsTo(UserProfile::class, 'user_id', 'user_id');
    }

    public function personalProfile()
    {
        return $this->belongsTo(UserProfilePersonal::class, 'user_id', 'user_id');
    }

    public function avatarVerf()
    {
        return $this->belongsTo(ProfileVerifyLog::class, 'user_id', 'user_id')
            ->where(['content_type' => ProfileVerifyLog::TYPE_REAL_AVATAR])
            ->where(['status' => ProfileVerifyLog::STATUS_OK])
            ->orderBy('id', 'desc')->limit(1);
    }
}
